import requests
# rag测试代码
import base64

img_path = "f:/data/image/test/card/1.jpg"
with open(img_path, 'rb') as img_file:
    img_base = base64.b64encode(img_file.read()).decode('utf-8')
# url = "http://192.168.132.92:3000/generate"
url = "http://192.168.132.92:3000/v1/chat/completions"
headers = {"Content-Type": "application/json"}
prompt = "这是一份人口登记卡片，第一步获取标题，第二步建立个人信息，获取上面的姓名、别名、性别、民族、出生日期、籍贯、出生地、职业、婚姻状况、现住址、登记日期。第三步建立户主信息，获取右上角户主姓名与户主关系信息。按照json中文格式数据。"
message = [
    {
        "role": "user",
        "content": [
            {"type": "text", "text": prompt},
            {
                "type": "image_url",
                "image_url": {
                    "url": f"data:image/jpeg;base64,{img_base}"
                }
            }
        ]
    }
]
payload = {
    "model": "vlm",
    "messages": message,
    "stream": False,
    "max_tokens": 1025,
    "temperature": 0.5,
    "top_p": 0.95,
    "presence_penalty": 0.5,
    "frequency_penalty": 0.5,
}
try:
    response = requests.post(
        url,
        headers=headers,
        json=payload,
        timeout=200
    )
    print(response.text)
except Exception as e:
    print(e)
